/**
 * Filename: TodayShowActivity.java
 *
 * @author Firefly
 * @contact postfirefly@163.com
 * @time 2016/3/9 2:57
 */
package com.github.postsanf.yinian.activity;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;

import com.facebook.drawee.view.SimpleDraweeView;
import com.github.postsanf.yinian.BaseApplication;
import com.github.postsanf.yinian.R;
import com.github.postsanf.yinian.constants.ACTIONs;
import com.github.postsanf.yinian.constants.CommonConstants;
import com.github.postsanf.yinian.constants.YNSingleton;
import com.github.postsanf.yinian.utils.ImageOptHelper;
import com.github.postsanf.yinian.utils.SpUtils;
import com.litesuits.http.HttpConfig;
import com.litesuits.http.LiteHttp;
import com.litesuits.http.exception.HttpException;
import com.litesuits.http.listener.HttpListener;
import com.litesuits.http.request.StringRequest;
import com.litesuits.http.request.param.HttpMethods;
import com.litesuits.http.response.Response;
import com.umeng.analytics.MobclickAgent;

import java.util.LinkedHashMap;

public class StealPhotoCourseBigShowActivity extends Activity {
    private SimpleDraweeView course_bigshow_iv;
    private String url;
    private BaseApplication application;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.yn_activity_stealphotoscourse_big);
        application = (BaseApplication) getApplication();
        if (getIntent() != null) {
            url = getIntent().getStringExtra("url");
        }
        initView();
        if (!SpUtils.getBoolean(StealPhotoCourseBigShowActivity.this, "fristCourseBigshow")) {
            AlertDialog.Builder builder = new AlertDialog.Builder(StealPhotoCourseBigShowActivity.this).setMessage("你已成功抽取了一张小忆本地照片的图片，去邀请你要偷看照片的好友加入圈子吧！")
                    .setPositiveButton(R.string.yn_app_zhidaole, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                        }
                    })
                    .setNegativeButton(R.string.yn_app_quyaoqing, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            Intent intent = new Intent(StealPhotoCourseBigShowActivity.this, InviteChooseActivity.class);
                            intent.putExtra(CommonConstants.YNDATAS, YNSingleton.getInstance().getCurAlbum());
                            startActivity(intent);
                        }
                    });
            builder.setCancelable(false);
            builder.show();
            SpUtils.put(StealPhotoCourseBigShowActivity.this, "fristCourseBigshow", true);
        }
    }

    private void initView() {
        course_bigshow_iv = (SimpleDraweeView) findViewById(R.id.course_bigshow_iv);
        ImageOptHelper.showFrescoStatus(Uri.parse(url), course_bigshow_iv, StealPhotoCourseBigShowActivity.this);
        findViewById(R.id.course_bigshow_close).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                OverCourse();
                startActivity(new Intent(StealPhotoCourseBigShowActivity.this, StealEachPerssionActivity.class));
                sendBroadcast(new Intent(ACTIONs.actionStealEachCourseFinish));
                finish();
            }
        });
        findViewById(R.id.course_bigshow_dismiss).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    private void OverCourse() {
        LinkedHashMap<String, String> mParam = new LinkedHashMap<>();
        mParam.put("userid", String.valueOf(application.getCurID()));
        String urlsto = getString(R.string.SLIVER_URL) + "FinishWatchPhotoTutorial";
        StringRequest req = new StringRequest(urlsto)
                .setMethod(HttpMethods.Post)
                .setParamMap(mParam)
                .setHttpListener(new HttpListener<String>(true, false, true) {
                    @Override
                    public void onSuccess(String s, Response<String> response) {
                        Log.i("xjs", "OverCourse===>" + s.toString());
                    }

                    @Override
                    public void onFailure(HttpException e, Response<String> response) {
                    }
                });
        LiteHttp.newApacheHttpClient(new HttpConfig(StealPhotoCourseBigShowActivity.this)).executeAsync(req);
    }

    public boolean onKeyDown(int keyCode, KeyEvent event) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_HOME:
                return true;
            case KeyEvent.KEYCODE_BACK:
                return true;
            case KeyEvent.KEYCODE_CALL:
                return true;
            case KeyEvent.KEYCODE_SYM:
                return true;
            case KeyEvent.KEYCODE_VOLUME_DOWN:
                return true;
            case KeyEvent.KEYCODE_VOLUME_UP:
                return true;
            case KeyEvent.KEYCODE_STAR:
                return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    // 友盟统计
    public void onResume() {
        super.onResume();
        MobclickAgent.onPageStart(this.getClass().getSimpleName());
        MobclickAgent.onResume(this);
    }

    public void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd(this.getClass().getSimpleName());
        MobclickAgent.onPause(this);
    }
}
